module Error

module ScriptErrors

#A generic class for reporting errors which deal with parsing files.
class ScriptError < Exception
  @mess
  @messprt
  @extra
  def cLASS
    return "Script"
  end
  def initialize(script,line,mess,*extra)
    @messprt=mess
    setMessage(line,script,extra) unless script===:"null.png"
  end
  def setMessage(script,line,extra=[],mes=@messprt)
    if extra.kind_of?(Array)
      extra.each_index { |i|
        mes.gsub!("ARG"+(i+1).to_s,extra[i].to_s)
      }
    else
      mes.gsub!("ARG1",extra.to_s)
    end
    @mess=script.to_s+": line "+line.to_s+": "+mes.to_s
    @messprt=mes.to_s
    @extra=extra
  end
  def message=(script,line,mess=@messprt,*extra)
    setMessage(line,script,extra)
  end
  def message
    return @mess 
  end
  def warn(script=:"null.png",ln=1,*extra)
    setMessage(script,ln,extra) unless script===:"null.png"
    $flog.warn(cLASS) {message}
    return self
  end
  def error(script=:"null.png",ln=1,*extra)
    setMessage(script,ln,extra) unless script===:"null.png"
    $flog.error(cLASS) {message}
    return self
  end
  #alias error log
end

class DataScriptError < ScriptError; def cLASS; return "Data Script"; end; end

class RubyScriptError < ScriptError; def cLASS; return "Ruby Script"; end; end

class SpeechScriptError < ScriptError; def cLASS; return "Speech Script"; end; end

class ObjectScriptError < ScriptError; def cLASS; return "Object Script"; end; end

IgnoringLine = SpeechScriptError.new(:"null.rb", 0, "Ignoring line")
BadGoto = SpeechScriptError.new(:"null.rb", 0, "Bad goto; the label 'ARG1' does not exist")
BadGosub = SpeechScriptError.new(:"null.rb", 0, "Bad gosub; the sub 'ARG1' does not exist")
BadReturn = SpeechScriptError.new(:"null.rb", 0, "Return statement outside of a sub")
NoAs = SpeechScriptError.new(:"null.rb", 0, "Expected 'as' in assignment")
UndefinedVar = SpeechScriptError.new(:"null.rb", 0, "Variable 'ARG1' is undefined")
ScriptArgs = SpeechScriptError.new(:"null.rb", 0, "Not enough arguments for 'script' command")
AskArgs = SpeechScriptError.new(:"null.rb", 0, "Not enough arguments for 'ask' command")
ImgArgs = SpeechScriptError.new(:"null.rb", 0, "Not enough arguments for 'img' command")
IfArgs = SpeechScriptError.new(:"null.rb", 0, "Not enough arguments for 'if' command")
LogicToken = SpeechScriptError.new(:"null.rb", 0, "'ARG1' is not a valid logic token. (Try '=' or '!=')")
ElIfArgs = SpeechScriptError.new(:"null.rb", 0, "Not enough arguments for 'elseif' command")
OPlaceIf = SpeechScriptError.new(:"null.rb", 0, "Cannot use 'ARG1' outside of if statement")
BadCommand = SpeechScriptError.new(:"null.rb", 0, "'ARG1' is not a valid command")
ExpectedVar = SpeechScriptError.new(:"null.rb", 0, "Expected variable")
ExpectedEndQuote = SpeechScriptError.new(:"null.rb", 0, "Expected end quote")
UnknownError = SpeechScriptError.new(:"null.rb", 0, "Unknown error")
ExtraChars = SpeechScriptError.new(:"null.rb", 0, "Extraneous characters")
BadYesSub = SpeechScriptError.new(:"null.rb", 0, "Bad sub for 'ask' (yes sub); the sub 'ARG1' does not exist")
BadNoSub = SpeechScriptError.new(:"null.rb", 0, "Bad sub for 'ask' (yes sub); the sub 'ARG1' does not exist")

RIgnoringLine = RubyScriptError.new(:"null.rb", 0, "Ignoring line")
IgnoringBlock = RubyScriptError.new(:"null.rb", 0, "Ignoring block around line ARG1")
BadSyntax = RubyScriptError.new(:"null.rb", 0, "Bad syntax")
MultRequire = RubyScriptError.new(:"null.rb", 0, "File 'ARG1' already required")
BadEval = RubyScriptError.new(:"null.rb", 0, "Potentially dangerous eval")
DoubleRubyBlock = RubyScriptError.new(:"null.rb", 0, "Already in a Ruby block")
BadCmd = RubyScriptError.new(:"null.rb", 0, "'ARG1' is not a valid command")
RubyError = RubyScriptError.new(:"null.rb", 0, "RubyError")

ExtraTokens = ObjectScriptError.new(:"null.rb", 0 ,"Extraneous tokens")
BadProperty = ObjectScriptError.new(:"null.rb", 0 ,"'ARG1' is not a vailid property for class 'ARG2'")
MultDeclarations = ObjectScriptError.new(:"null.rb", 0 ,"Multiple definitions of 'ARG1'")
BadParam = ObjectScriptError.new(:"null.rb", 0 ,"Invalid parameter 'ARG1'")
ExpectedVal = ObjectScriptError.new(:"null.rb", 0 ,"Expected value for paremeter 'ARG1'")
ExpectedClass = ObjectScriptError.new(:"null.rb", 0 ,"Expected class name")
BadClass = ObjectScriptError.new(:"null.rb", 0 ,"'ARG1' is not a valid object class")
TooManyArgs = ObjectScriptError.new(:"null.rb", 0 ,"Too many arguments (expected at most ARG1)")
TooFewArgs = ObjectScriptError.new(:"null.rb", 0 ,"Not enough arguments (expected at least ARG1)")
BadEnum = ObjectScriptError.new(:"null.rb", 0 ,"Invalid enumerated type: 'ARG1'")

class IniFileError < ScriptError; def cLASS; return "INI File"; end; end

OptionMissing = IniFileError.new(:"null.ini", 0, "Manditory parameter missing: 'ARG1::ARG2'")
BadOptionValue = IniFileError.new(:"null.ini", 0, "Invalid parameter value: 'ARG3' given as a value for for 'ARG1::ARG2'")

class ValueError < Exception
  
end

class FileError < Exception

end

end #module ScriptErrors

include ScriptErrors

end #module Error

include Error